package Mytest.day02;

import java.util.ArrayList;

//添加老师:通过键盘录入老师信息(id，name，age，birthday)
// 使用数组存储老师信息,要求老师的id不能重复
// 删除老师:通过键盘录入要删除老师的id值,将该老师从数组中移除,如果录入的id在数组中不存在,需要重新录 入
// 修改老师:通过键盘录入要修改老师的id值和修改后的老师信息 将数组中该老师的信息修改,如果录入的id在数组中不存在,需要重新录入
// 查询老师:将数组中存储的所有老师的信息输出到控制台
public class TeacherService {
    public static ArrayList<Teacher> findAllTeacher() {
        ArrayList<Teacher> list = TeacherDao.findAllTeacher();
        return list;

    }

    public boolean isExists(String id) {
        ArrayList<Teacher> list = TeacherDao.findAllTeacher();
        boolean exists = false;
        for (int i = 0; i < list.size(); i++) {
            Teacher t = list.get(i);
            if (t.getId().equals(id)) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    public boolean addTeacher(Teacher t) {
        TeacherDao dao = new TeacherDao();
        boolean result = dao.addTeacher(t);
        return result;
    }

    public boolean deleteTeacher(String id) {
        boolean r = TeacherDao.deleteTeacher(id);
        return r;
    }

    public void updateTeacher(String id, Teacher newTeacher) {
        TeacherDao.updateTeacher(id, newTeacher);
    }
}
